package com.chenggcode.simple.log;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.io.Serial;
import java.io.Serializable;

/**
 * @author Chenggcode
 * @date 2025/6/19 11:56
 */
@Tag(name = "日志控制器", description = "用于测试日志记录功能")
@Slf4j
@RestController
@RequestMapping("/log")
@RequiredArgsConstructor
public class LogController {

    @Operation(summary = "测试日志记录", description = "接收一个参数并记录日志")
    @GetMapping("/test")
    public String testLog(@RequestParam("p") String p) {
        log.info("p: {}", p);
        return "Log controller is working!";
    }

    @PostMapping
    @Operation(summary = "测试日志记录", description = "接收一个请求体并记录日志")
    public String testLog(@RequestBody TestReq req) {
        log.info("Received request: {}", req);
        return "Log controller is working!";
    }

    @Data
    public static class TestReq implements Serializable {
        @Serial
        private static final long serialVersionUID = 1L;

        private String name;

        private Integer age;

        private String sex;

        private String address;

        private String phone;

    }
}
